package com.cnap;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import com.cnap.controller.ApplicationController;
import com.cnap.utils.TokenUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.test.annotation.Rollback;

@SpringBootTest
//@WebAppConfiguration
@Rollback
public class CnapApplicationTests {

    @Autowired
    private ApplicationController applicationController;


    public static HttpRequest mockRequest;
    public static MockedStatic<FileUtil> fileUtilMockedStatic;
    //public static MockedStatic<SpringUtil> spingUtilMockedStatic;

    static {
        String token = "eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NjUyMjI3ODksInN1YiI6ImFkbWluIiwiaWF0IjoxNjY1MjA4Mzg5MzE1fQ._FxOBy7ChUuuSOYnAJOuK1S_IMdkH45VMC1Sd59bSUY";
        MockedStatic<TokenUtils> tokenUtilsMockedStatic = Mockito.mockStatic(TokenUtils.class);
        //spingUtilMockedStatic = Mockito.mockStatic(SpringUtil.class);
        tokenUtilsMockedStatic.when(TokenUtils::getTOKEN).thenReturn(token);
        tokenUtilsMockedStatic.when(TokenUtils::getUserName).thenReturn("admin");

        mockRequest = Mockito.mock(HttpRequest.class);
        MockedStatic<HttpRequest> mockedStatic = Mockito.mockStatic(HttpRequest.class);
        mockedStatic.when(() -> HttpRequest.post(Mockito.anyString())).thenReturn(mockRequest);
        mockedStatic.when(() -> HttpRequest.get(Mockito.anyString())).thenReturn(mockRequest);
        mockedStatic.when(() -> HttpRequest.delete(Mockito.anyString())).thenReturn(mockRequest);
        Mockito.when(mockRequest.header(HttpHeaders.AUTHORIZATION, token)).thenReturn(mockRequest);
        Mockito.when(mockRequest.body(Mockito.anyString())).thenReturn(mockRequest);

        fileUtilMockedStatic = Mockito.mockStatic(FileUtil.class);
    }

    @Test
    void contextLoads() {
        Assertions.assertNotNull(applicationController);
    }


}
